<?php


class adminAction extends T {

	function __init__() {
	
		$this->php->loaddb()->loadview()->helper("function")->init();
	
	}
	
	function index() { $this->php->view->display("admin/index.php");}
	function ht_top(){ $this->php->view->display("admin/ht_top.php");}
	function ht_menu(){ $this->php->view->display("admin/ht_menu.php");}
	function ht_main(){ $this->php->view->display("admin/ht_main.php");}
	function ht_footer(){ $this->php->view->display("admin/ht_footer.php");}
	
	function tree() {
		$this->php->db->settable("www_tree")->init();
		
		$list = $this->php->db->select();
		
		$treelist = list_to_tree($list);
		
		
		$this->php->view->assign("treelist",$treelist);
		$this->php->view->display("admin/tree.php");
	
	}
	
	function tree_add() {
		$this->php->view->display("admin/tree_add.php");
	}
	function tree_add_do() {
		$this->insert("www_tree",$_POST,0,"?a=tree",5,"添加成功，5秒后跳转");
	}
	function tree_edit() {
		$this->php->view->display("admin/tree_edit.php");
	}
	function tree_update() {
		$this->update("www_tree",$_POST,0,"?a=tree",3,"3秒后跳转");
	}
	function tree_del() {
		$this->delect("www_tree");
	}


	/*
		
		news

	*/

	function news_index() {
		$this->view->display("admin/news_index.php");
	}

	
	function news_add() {
		//得到新闻分类
		$this->php->M("tree")->news_tree();

		$this->view->display("admin/news_add.php");
	}

	function news_add_do() {
	
		$this->php->M("news")->news_add();
	
	}

	function news_list() {

		$this->php->M("news")->news_list();

		$this->view->display("admin/news_list.php");

	}

	function news_edit() {
		
		$id = intval($_GET["id"]);

		$this->php->M("tree")->news_tree();
		$vo = $this->php->M("news")->news_find($id);


		$this->view->assign("vo",$vo);
		$this->view->display("admin/news_edit.php");
	}

	function news_update() {
		$id = intval($_POST["id"]);
		unset($_POST["id"]);

		$this->php->M("news")->news_update($id);

	}

	function news_del() {

		$this->delect("www_news");
	}
	/*
		
		curd
	
	*/
	function insert($table,$data,$qz=0,$url=null,$time=3,$message="ok") {
		
		if($qz == 0){
		
		}else {
			$this->db->setqz($qz)->init();
		}
			
			
		$this->db->settable($table)->init();
		if($this->db->insert($data)) {
			
			if(empty($url)) {
				echo $message;
			}else {
				$this->php->redirect($url,$time,$message);
			}
			
		}else {
		
			echo "insert error";
		
		}
	
	}
	public function update($table,$data,$qz=0,$url=null,$time=3,$message="ok") {

		if($qz == 0){
		
		}else {
			$this->db->setqz($qz)->init();
		}
		
		$id=$data["id"];
		unset($data["id"]);
			
			
		$this->db->settable($table)->init();
		if($this->db->where("id =".$id)->update($data)) {
			
			if(empty($url)) {
				echo $message;
			}else {
				$this->php->redirect($url,$time,$message);
			}
			
		}else {
		
			echo "update error";
		
		}

	}
	
	function delect($table) {
	
		if($this->db->settable($table)->where("id=".$_GET["id"])->delete()){
			echo 'ok';
		}
		
	}
	
	function __destruct () {
		
		$str = $this->php->db->getMsg();
		echo "<hr />";
		echo $str;
	
	
	}
	
	











}